package cn.ichensw.otherworldlystationbackend.controller;

import cn.ichensw.otherworldlystationbackend.common.BaseResponse;
import cn.ichensw.otherworldlystationbackend.common.ResultUtils;
import cn.ichensw.otherworldlystationbackend.model.dto.bangumi.BangumiSearchRequest;
import cn.ichensw.otherworldlystationbackend.model.dto.bangumi.BangumiSearchV0Request;
import cn.ichensw.otherworldlystationbackend.model.vo.bangumi.BangumiCalendarVO;
import cn.ichensw.otherworldlystationbackend.model.vo.bangumi.BangumiSearchSubjectSmallVO;
import cn.ichensw.otherworldlystationbackend.model.vo.bangumi.BangumiSubjectDetailVO;
import cn.ichensw.otherworldlystationbackend.service.BangumiService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Bangumi接口Controller
 *
 * @author csw
 */
@Api(value = "Bangumi查询接口", tags = "BangumiController")
@RestController
@RequestMapping("/bangumi")
public class BangumiController {


    @Resource
    private BangumiService bangumiService;

    /**
     * 根据关键字搜索条目(动漫)
     * 缺点：数据缺少airDate和airWeekday信息
     * 优点：简单方便
     *
     * @param request 请求参数
     * @return 条目列表
     */
    @ApiOperation("根据关键字搜索条目")
    @PostMapping("/search/subject")
    public BaseResponse<Page<BangumiSearchSubjectSmallVO>> searchSubject(@RequestBody BangumiSearchRequest bangumiSearchRequest, HttpServletRequest request) {
        return ResultUtils.success(bangumiService.searchSubject(bangumiSearchRequest, request));
    }


    /**
     * 搜索条目(复杂搜索)试验性API 随时可能失效
     * 优点：数据完整
     * 缺点：复杂、可能失效
     *
     * @param request 请求参数
     * @return 条目列表
     */
    @ApiOperation("搜索条目(复杂搜索)-试验性API")
    @PostMapping("/v0/search/subject")
    public BaseResponse<Page<BangumiSearchSubjectSmallVO>> searchSubjectV0(@RequestBody BangumiSearchV0Request bangumiSearchV0Request, HttpServletRequest request) {
        return ResultUtils.success(bangumiService.searchSubjectV0(bangumiSearchV0Request, request));
    }

    /**
     * 每日放送
     *
     * @return 条目列表
     */
    @ApiOperation("每日放送")
    @GetMapping("/calendar")
    public BaseResponse<List<BangumiCalendarVO>> calendar() {
        return ResultUtils.success(bangumiService.calendar());
    }

    /**
     * 根据ID获取条目信息
     *
     * @return 条目列表
     */
    @ApiOperation("根据ID获取条目信息")
    @GetMapping("/v0/subject/{subject_id}")
    public BaseResponse<BangumiSubjectDetailVO> subjectsDetail(@PathVariable("subject_id") Integer subjectId, HttpServletRequest request) {
        return ResultUtils.success(bangumiService.subjectsDetail(subjectId, request));
    }

}
